var service_common = require("common.js");

//对外公开的方法
module.exports = {
  getTeamHB: getTeamHB,
  getJoinTeamList: getJoinTeamList,
  getMyTeamList: getMyTeamList,
  getTeamList: getTeamList,
  setSaveTeam: setSaveTeam,
  setJoinTeam: setJoinTeam,
  setQuitTeam: setQuitTeam,
  setCreateTeam: setCreateTeam,
  getTeamInfo: getTeamInfo,
  getTeamMembers: getTeamMembers
}

/**
 * 获取战队海报图
 */
function getTeamHB(name, id) {
  console.log(service_common.getUrl("user.getTeamHB") + "?zhan_dui_share_open_id=" + getApp().globalData.openid + "&name=" + name + "&id=" + id + "&uid=" + getApp().globalData.userInfo.id);
  wx.previewImage({
    urls: [service_common.getUrl("user.getTeamHB") + "?zhan_dui_share_open_id=" + getApp().globalData.openid + "&name=" + name + "&id=" + id + "&uid=" + getApp().globalData.userInfo.id],
  })
}

/**
 * 获取加入的战队
 */
function getJoinTeamList(cb) {
  service_common.fetchData(
    service_common.getUrl("user.getJoinTeamList"),
    {
      openid: getApp().globalData.openid
    },
    function (res) {
      cb(res);
    },
    "GET"
  )
}

/**
 * 获取我创建的战队
 */
function getMyTeamList(cb) {
  service_common.fetchData(
    service_common.getUrl("user.getMyTeamList"),
    {
      openid: getApp().globalData.openid
    },
    function (res) {
      cb(res);
    },
    "GET"
  )
}

/**
 * 获取战队列表
 */
function getTeamList(page, cb) {
  service_common.fetchData(
    service_common.getUrl("user.getTeamList"),
    {
      openid: getApp().globalData.openid,
      page: page
    },
    function (res) {
      cb(res);
    },
    "GET"
  )
}
/**
 * 保存战队
 */
function setSaveTeam(id, team_name, team_info, cb) {
  service_common.fetchData(
    service_common.getUrl("user.setSaveTeam"),
    {
      openid: getApp().globalData.openid,
      id: id,
      team_name: team_name,
      team_info: team_info
    },
    function (res) {
      cb(res);
    },
    "GET"
  )
}
/**
 * 加入战队
 */
function setJoinTeam(id, cb) {
  service_common.fetchData(
    service_common.getUrl("user.setJoinTeam"),
    {
      openid: getApp().globalData.openid,
      id: id
    },
    function (res) {
      cb(res);
    },
    "GET", true
  )
}
/**
 * 退出战队
 */
function setQuitTeam(id, cb) {
  service_common.fetchData(
    service_common.getUrl("user.setQuitTeam"),
    {
      openid: getApp().globalData.openid,
      id: id
    },
    function (res) {
      cb(res);
    },
    "GET", true
  )
}
/**
 * 创建战队
 */
function setCreateTeam(team_name, team_info, cb) {
  service_common.fetchData(
    service_common.getUrl("user.setCreateTeam"),
    {
      openid: getApp().globalData.openid,
      team_name: team_name,
      team_info: team_info
    },
    function (res) {
      cb(res);
    },
    "GET",true
  )
}
/**
 * 获取战队信息
 */
function getTeamInfo(id, cb) {
  service_common.fetchData(
    service_common.getUrl("user.getTeamInfo"),
    {
      my_openid: getApp().globalData.openid,
      id: id
    },
    function (res) {
      cb(res);
    },
    "GET"
  )
}

/**
 * 获取战队成员
 */
function getTeamMembers(id, page, cb) {
  service_common.fetchData(
    service_common.getUrl("user.getTeamMembers"),
    {
      my_openid: getApp().globalData.openid,
      page: page,
      id: id
    },
    function (res) {
      cb(res);
    },
    "GET"
  )
}